package cn.edu.hqu.example.bj.experiment5;

import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.Toast;


public class MainActivity extends AppCompatActivity {

    SharedPreferences preferences;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        preferences=this.getSharedPreferences("count",MODE_PRIVATE);

        //text.setText("hello world usecount!");
        //读取SharedPerences里的count数据
        int count=0;
        //显示程序以前使用的次数
        Toast.makeText(this,"程序以前被使用了"+count+"次。",Toast.LENGTH_LONG).show();

        SharedPreferences.Editor editor=preferences.edit();
        editor.putInt("count",++count);
        editor.commit();

    }
}
